home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: MegaDisc / MegaDisc 06 (1988)(MegaDisc Digital Publishing)(AU)[m][WB].zip / MegaDisc 06 (1988)(MegaDisc Digital Publishing)(AU)[m][WB].adf / ARTICLES / BatchFiles < prev    next >
Text File  |  1988-03-28  |  12KB  |  287 lines

  1.  
  2.  
  3.           CREATING COMMAND SEQUENCE FILES (CSF) OR BATCH FILES
  4.  
  5.                                                  by Tim Strachan
  6.  
  7.     INTRODUCTION
  8.  
  9.         In your normal use of DOS, you will enter a command and execute it
  10.     immediately. This is fine for most uses, but occasionally you'll find
  11.     that you need to repeat a series of commands regularly, or that you'd
  12.     like to customise the startup-sequence of your WorkBench disk. In fact,
  13.     the startup-sequence is the most significant of CSFs, and being able to
  14.     manipulate and change it is one of the fundamental abilities you should
  15.     develop.
  16.  
  17.         In this tutorial you'll learn how to do so, and all the necessary
  18.     tools are available on your Workbench disk. You will need to know the
  19.     basic structure of CSFs, and how to edit them. There are some special
  20.     CSF commands, such as EXECUTE, SKIP, and so forth, which are used in
  21.     conjunction with normal CLI commands, and there is a SCREEN EDITOR,
  22.     called ED in your C directory which allows you to create or change such
  23.     files, as well as any other text file. However, you can create a text
  24.     file of any kind with a Word Processor which allows you to save a file
  25.     in strict text form (as ASCII characters).
  26.  
  27.  
  28.     FUNDAMENTALS
  29.  
  30.     1. USING ED, THE TEXT EDITOR
  31.  
  32.         As mentioned above, you will have to be able to create a text file
  33.     with a text editor, and your Workbench disk comes with ED, a basic text
  34.     editor quite capable of this and more. There is another "Line Editor"
  35.     called EDIT in your C directory as well, but it is not easy to learn.
  36.     In fact, it would be worthwhile buying a commercial editor such as
  37.     TxED, or finding one of the excellent editors in the public domain,
  38.     which make use of the Workbench interface. In the meantime however, if
  39.     you wish to create a new file, or edit an old one, using ED, simply
  40.     enter in the CLI
  41.     ED FILENAME
  42.     for example
  43.     ED df0:s/startup-sequence
  44.     if you want to change your startup-sequence (do it with a COPY of your
  45.     Workbench!).
  46.     Now just enter text from the keyboard to create a new file. In the case
  47.     of editing an existing file, use the cursor keys, DEL and BACKSPACE and
  48.     RETURN keys to change and add text.
  49.     Let's say that we want to create a file called MAKERAM which will copy
  50.     all the CLI commands into RAM, and run them from there instead of from
  51.     your disk (see further below). Enter the following (Hit RETURN each
  52.     time):
  53.  
  54.     ED S/MAKERAM
  55.     (You'll be presented with the ED screen.)
  56.     MAKEDIR RAM:C
  57.     COPY SYS:C RAM:C
  58.     ASSIGN C: RAM:C
  59.  
  60.     You now have a 3-line batch file. If you notice a spelling mistake,
  61.     simply use the cursor keys to reach the mistake and Backspace or Delete
  62.     the offending letter(s).
  63.     Now you must save the file, so press ESC and you'll find the cursor
  64.     drops to the bottom of the screen where further commands (called
  65.     EXTENDED COMMANDS as distinct from IMMEDIATE COMMANDS which you use
  66.     when on the ED screen itself) may be entered. The command to save is
  67.     simply X, followed by RETURN. This will exit ED, while saving your file
  68.     under the name you first gave it in the directory you specified - in
  69.     this case MAKERAM in the S directory.
  70.  
  71.     * NOTE - The ED.REFERENCE article on MD2 lists all the available
  72.     commands for ED, and if you decide to stay with ED, make sure you
  73.     experiment with them, as they allow you many powerful possibilities for
  74.     text editing.
  75.  
  76.  
  77.     2. CREATING A COMMAND SEQUENCE FILE
  78.  
  79.         You must create a file with one or more CLI commands, with one
  80.     command to a line, and with a RETURN character at the end of each line.
  81.     Having created the file, it is a good idea to save it to the S
  82.     directory of your disk, since AmigaDOS looks there automatically when
  83.     you use the command EXECUTE. This means that you don't have to type out
  84.     the full PATHNAME of the file - ie, where it is, such as
  85.     df1:utilities/myCSF                      Instead, you'll simply type
  86.     EXECUTE myCSF
  87.     The command EXECUTE (which is detailed below) must precede any CSF,
  88.     just as it is automatically used when booting up with any Workbench
  89.     disk.  You can also attach comments to your CSF by simply typing in a
  90.     semi-colon before any comment you make. For example:
  91.  
  92.     MAKEDIR RAM:C               ;make directory c on the Ram disk
  93.     COPY SYS:C RAM:C ALL        ;copy all your c commands across
  94.     ASSIGN C: RAM:C             ;re-assign your c: directory to ram:c
  95.  
  96.     This CSF is a most useful one to have, since it allows you to copy all
  97.     your CLI commands to a C directory which you've created on your Ram
  98.     disk, and then, the last line tells the system to look in the Ram:c
  99.     directory when it wants to find a CLI command. These three lines oould
  100.     be typed into your startup-sequence to be executed automatically each
  101.     time that you boot up; or you could simply name this file MAKERAM or
  102.     some such name, and EXECUTE it whenever you want to.
  103.  
  104.     Such a file can be refined as you wish - it may be that you are
  105.     memory-conscious, and don't want to have a lot of your precious Ram
  106.     taken up by commands that you rarely use. So you could adapt this CSF
  107.     to copy only those commands that you use regularly into the RAM:C
  108.     directory, by replacing the second line above by the following series:
  109.  
  110.     COPY SYS:C/CD RAM:C
  111.     COPY SYS:C/DIR RAM:C
  112.     COPY SYS:C/TYPE RAM:C
  113.     COPY SYS:C/COPY RAM:C
  114.  
  115.     You could add to this series according to which commands you'd normally
  116.     use. Now such a file requires the COPY command to be read from your
  117.     disk each time, so we could add a further refinement by copying the
  118.     COPY command directly to RAM:C first, and then ASSIGNing a short alias
  119.     to it, to speed up the processes of both executing the command and of
  120.     typing it in, as follows:
  121.  
  122.     MAKEDIR RAM:C
  123.     COPY SYS:C/COPY RAM:C
  124.     ASSIGN CP: RAM:C/COPY
  125.     CP: SYS:C/CD RAM:C
  126.     CP: SYS:C/DIR RAM:C
  127.     CP: SYS:C/TYPE RAM:C
  128.     ASSIGN C: RAM:C
  129.  
  130.     A further refinement now could be to insert the line
  131.     CD SYS:C
  132.     after the first line above - this would make it unecessary to type in
  133.     the  "SYS:C" before each command to be copied, since you'd already be
  134.     in the directory that you're copying from.
  135.  
  136.  
  137.  
  138.     It may be that you've got to do some memory-intensive work, such as
  139.     animations, and want to use all the memory you've got. You'll want to
  140.     remove all those commands on the RAM disk, so you may make up a CSF
  141.     like the following (and keep it in your S directory as usual):
  142.  
  143.     ECHO "CLEARING THE RAM DISK"
  144.     CD DF0:
  145.     ASSIGN C: SYS:C
  146.     DELETE RAM:C
  147.     ECHO "ALL DONE NOW"
  148.  
  149.     Here's another approach to achieving the same objective, except that
  150.     this time, some more use has been made of the ASSIGN and ECHO commands.
  151.     Note that you could also use the SAY command, so that you're told
  152.     what's happening as it happens.
  153.  
  154.     COPY DF0:C/ECHO TO RAM:C
  155.     COPY DF0:C/COPY TO RAM:C
  156.     COPY DF0:C/ASSIGN TO RAM:C
  157.     ASSIGN C: RAM:C
  158.     ECHO "MAKING A RAM DISC"
  159.     ECHO " "
  160.     ECHO "COPYING SYS/C TO RAM"
  161.     COPY SYS:C RAM:C ALL QUIET
  162.     ECHO ""
  163.     ECHO "ASSIGNED C: TO RAM:C"
  164.     ECHO ""
  165.     ECHO "ALL DONE NOW"
  166.  
  167.  
  168.     In other words, it is up to you and what you want to achieve, and the
  169.     best way of getting what you want is to experiment.
  170.  
  171.  
  172.     3. FURTHER CAPABILITIES OF BATCH FILES
  173.  
  174.         Although any CLI command can be used in a command file (including
  175.     the command EXECUTE itself), certain commands were made especially for
  176.     use in a command file (for futher information, see the listing in this
  177.     section):
  178.  
  179.     IF       these allow you to test conditions occurring during  execution
  180.     ELSE     of the sequence, and to act on the results.
  181.     ENDIF
  182.  
  183.     FAILAT   sets the level of failure at which the sequence  will stop.
  184.     QUIT     QUIT will force a stop with a return code you choose.
  185.  
  186.     SKIP     allows you to mark areas (LAB) in your sequence and then jump
  187.     LAB      forward to them (SKIP).
  188.  
  189.     WAIT     stops sequence  processing for a period of time, or until a
  190.              specified time of day.
  191.  
  192.     ECHO     lets you display text strings, such as prompts, from within
  193.              your sequence.
  194.  
  195.     ASK      lets you branch either of two ways with a Y(ES) or N(O)
  196.  
  197.  
  198.  
  199.  
  200.     PASSING INSTRUCTIONS TO BATCH FILES
  201.  
  202.     The EXECUTE Command itself recognises various DIRECTIVES, which allow
  203.     you to pass words and substitute them in the various command lines in
  204.     the CSF. Thus you can use one CSF for a variety of tasks if you design
  205.     your CSF well.  A  dot command MUST be on the first  line of the file.
  206.     It can be any command, but is usually either a  parameter template
  207.     (.KEY) or a comment.
  208.  
  209.  
  210.     .KEY or .K      This defines the names of the parameters to be passed.
  211.                     This is the most important of the dot commands.
  212.  
  213.                     If this is placed at the beginning of your CSF, then
  214.                     your CSF will take whatever file follows your CSF name
  215.                     and substitute it wherever it sees "filename1" in the
  216.                     batch file.
  217.                     EXAMPLE:  .KEY filename1
  218.                               COPY <filename1> TO :MYDOCS
  219.                     To use this CSF (whose name is BACKUP, say), enter
  220.                     EXECUTE BACKUP Letter
  221.                     Now the file LETTER is copied to the MYDOCS directory
  222.                     on the current disk (assuming it exists).
  223.  
  224.     .DEF <name> <value>  defines a global default parameter value
  225.                     (the $ default is used on that line only)
  226.                     EXAMPLE:  .DEF filename1 #?.doc
  227.                     If this were inserted in the above example, then if no
  228.                     specific filename were given, then #?.doc  would be
  229.                     substituted for the filename, and all files of that
  230.                     pattern would be copied to the :MYDOCS directory.
  231.                     This gives you a failsafe option, since otherwise all
  232.                     files in the current directory would be acted upon.
  233.  
  234.     .DOT <char>     redefines the command indicator character
  235.                     (default is dot '.')
  236.                     EXAMPLE:  .DOT @    then use  @KEY from,to
  237.  
  238.     .BRA <char>     redefines the left & right parameter indicators
  239.     .KET <char>     (default are '<' and '>')
  240.                     This can be useful if you want to include a name which
  241.                     has the current default bracket characters (ie, < & > )
  242.                     EXAMPLE:  .BRA [.
  243.                     This will change the left angle bracket character (<)
  244.                     to the the left square bracket character. Note the
  245.                     period after [ .
  246.  
  247.     .DOLLAR <char>  redefines the default indicator character
  248.                     (default is dollar '$')
  249.                     EXAMPLE:  ED <file$work.doc>
  250.                     This substitutes "file", but if "file" is not given,
  251.                     will substitute "work.doc" .
  252.  
  253.     . <text>        indicates that the rest of the line is a comment.
  254.                     EXAMPLE:  . Dot, followed by space is a comment.
  255.  
  256.     .<return>       indicates a blank comment line.
  257.  
  258.  
  259.  
  260.     FURTHER EXAMPLES
  261.  
  262.     The  following sequence is used to delete a file,  but make a
  263.     backup first in the :T subdirectory.
  264.  
  265.     . Delete a file, but make a backup first
  266.     .
  267.     .KEY from,to
  268.     IF "<from>" EQ ""
  269.        QUIT 20            ;this terminates the CSF immediately
  270.     ENDIF
  271.     IF "<to>" EQ ""
  272.        COPY <from> TO :T/<from>.Old
  273.        DELETE <from>
  274.        QUIT
  275.     ENDIF
  276.     COPY <from> TO :T/<to>
  277.     DELETE <from>
  278.     QUIT
  279.  
  280.     This would be entered as follows (if the name of the CSF is BACKUP):
  281.     EXECUTE BACKUP filename1,filename2
  282.  
  283.  
  284.  
  285. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ END OF BATCHFILES ~~~~~~~~~~~~~~~~~~~~~~~~~~
  286.  
  287.